/**
 * @file bsp_can.h
 * @brief CAN通信驱动
 */

#ifndef __BSP_CAN_H__
#define __BSP_CAN_H__

#include "n32g430.h"

/* CAN 引脚定义 */
#define CAN_TX_GPIO_PORT        GPIOB
#define CAN_TX_GPIO_PIN         GPIO_PIN_9
#define CAN_TX_GPIO_AF          GPIO_AF6_CAN
#define CAN_RX_GPIO_PORT        GPIOB
#define CAN_RX_GPIO_PIN         GPIO_PIN_8
#define CAN_RX_GPIO_AF          GPIO_AF6_CAN

/* CAN 过滤器配置 */
#define CAN_FILTER_BANK         0
#define CAN_FILTER_ID_HIGH      0x0000
#define CAN_FILTER_ID_LOW       0x0000
#define CAN_FILTER_MASK_HIGH    0x0000
#define CAN_FILTER_MASK_LOW     0x0000

/* CAN消息回调函数类型定义 */
typedef void (*CAN_RxCallback)(uint32_t id, uint8_t *data, uint8_t len);

/* CAN消息缓冲区定义 */
#define CAN_RX_BUFFER_SIZE    32  // 接收缓冲区大小

/* CAN消息结构体 */
typedef struct {
    uint32_t id;      // 消息ID
    uint8_t  data[8]; // 数据
    uint8_t  len;     // 数据长度
} CAN_Message;

/* 函数声明 */
void BSP_CAN_Init(void);
uint8_t BSP_CAN_Transmit(uint32_t id, uint8_t *data, uint8_t len);
void BSP_CAN_RegisterCallback(CAN_RxCallback callback);
uint8_t BSP_CAN_GetMessage(CAN_Message* msg);  // 从缓冲区获取消息

#endif /* __BSP_CAN_H__ */ 